//
//  recruitViewController.m
//  Project
//
//  Created by iD Student on 7/30/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "recruitViewController.h"

@interface recruitViewController ()

@end

@implementation recruitViewController
@synthesize fighterW;
@synthesize fighterS;
@synthesize fighterI;
@synthesize archerW;
@synthesize archerS;
@synthesize archerI;
@synthesize cavalryW;
@synthesize cavalryS;
@synthesize cavalryI;
@synthesize catapultW;
@synthesize catapultS;
@synthesize catapultI;
@synthesize infoScroll;
@synthesize infoText;
@synthesize scrollbutton;
@synthesize woodCount;
@synthesize stoneCount;
@synthesize ironCount;
@synthesize fighterAmount;
@synthesize archerAmount;
@synthesize cavalryAmount;
@synthesize catapultAmount;
@synthesize recruitHelp1;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    fighterAmount.text = [NSString stringWithFormat: @"%d", fighterAmt];
    archerAmount.text = [NSString stringWithFormat: @"%d", archerAmt];
    cavalryAmount.text = [NSString stringWithFormat: @"%d", cavalryAmt];
    catapultAmount.text = [NSString stringWithFormat: @"%d", catapultAmt];
    scrollbutton.hidden = TRUE;
    infoScroll.hidden = TRUE;
    infoText.hidden = TRUE;
    
    if (cheapTroops == TRUE)
    {
        fighterW.text = [NSString stringWithFormat:@"%i", 20];
        fighterI.text = [NSString stringWithFormat:@"%i", 25];
        fighterS.text = [NSString stringWithFormat:@"%i", 30];
        archerW.text = [NSString stringWithFormat:@"%i", 40];
        archerI.text = [NSString stringWithFormat:@"%i", 25];
        archerS.text = [NSString stringWithFormat:@"%i", 30];
        cavalryW.text = [NSString stringWithFormat:@"%i", 55];
        cavalryI.text = [NSString stringWithFormat:@"%i", 30];
        cavalryS.text = [NSString stringWithFormat:@"%i", 70];
        catapultW.text = [NSString stringWithFormat:@"%i", 100];
        catapultI.text = [NSString stringWithFormat:@"%i", 170];
        catapultS.text = [NSString stringWithFormat:@"%i", 65];
    }
    
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [self setWoodCount:nil];
    [self setStoneCount:nil];
    [self setIronCount:nil];
    [self setFighterAmount:nil];
    [self setArcherAmount:nil];
    [self setCavalryAmount:nil];
    [self setCatapultAmount:nil];
    [self setFighterW:nil];
    [self setFighterS:nil];
    [self setFighterI:nil];
    [self setArcherW:nil];
    [self setArcherS:nil];
    [self setArcherI:nil];
    [self setCavalryW:nil];
    [self setCavalryS:nil];
    [self setCavalryI:nil];
    [self setCatapultW:nil];
    [self setCatapultS:nil];
    [self setCatapultI:nil];
    [self setInfoScroll:nil];
    [self setInfoText:nil];
    [self setScrollbutton:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)back:(id)sender 
{
    [self dismissModalViewControllerAnimated:YES];
}
- (void)dealloc {
    [woodCount release];
    [stoneCount release];
    [ironCount release];
    [fighterAmount release];
    [archerAmount release];
    [cavalryAmount release];
    [catapultAmount release];
    [fighterW release];
    [fighterS release];
    [fighterI release];
    [archerW release];
    [archerS release];
    [archerI release];
    [cavalryW release];
    [cavalryS release];
    [cavalryI release];
    [catapultW release];
    [catapultS release];
    [catapultI release];
    [infoScroll release];
    [infoText release];
    [scrollbutton release];
    [super dealloc];
}
- (IBAction)fighterBuy:(id)sender 
{
    if (infoFighter == FALSE)
    {
        infoScroll.hidden = FALSE;
        infoText.hidden = FALSE;
        scrollbutton.hidden = FALSE;
        infoFighter = TRUE;
        infoText.text = @"Fighter's are a cheap unit with offensive and defensive strengths, specialized in offense. They are decent for plundering resources but far outclassed by Cavalry. For exact stats, see the help guide.";
    }
    else 
    {
        if (cheapTroops == FALSE && wood >= 30 && stone >= 35 && iron >= 40)
        {
            fighterAmt ++;
            fighterAmount.text = [NSString stringWithFormat: @"%d", fighterAmt];
            wood = wood - 30;
            stone = stone - 35;
            iron = iron - 40;
            woodCount.text = [NSString stringWithFormat:@"%d", wood];
            stoneCount.text = [NSString stringWithFormat:@"%d", stone];
            ironCount.text = [NSString stringWithFormat:@"%d", iron];
        }
        else if (cheapTroops == TRUE && wood >= 20 && stone >= 25 && iron >= 30)
        {
            fighterAmt ++;
            fighterAmount.text = [NSString stringWithFormat: @"%d", fighterAmt];
            wood = wood - 20;
            stone = stone - 25;
            iron = iron - 30;
            woodCount.text = [NSString stringWithFormat:@"%d", wood];
            stoneCount.text = [NSString stringWithFormat:@"%d", stone];
            ironCount.text = [NSString stringWithFormat:@"%d", iron];
        }
    }
}

- (IBAction)archerBuy:(id)sender 
{
    if (infoArcher == FALSE)
    {
        infoScroll.hidden = FALSE;
        infoText.hidden = FALSE;
        scrollbutton.hidden = FALSE;
        infoArcher = TRUE;
        infoText.text = @"Archer's are the main defensive unit in this game. They have strong defensive stats and low costs, but are useless while attacking. They also have low plunder rates. For exact stats, see the help guide.";
    }
    else
    {
        if (cheapTroops == FALSE && wood >= 55 && stone >= 35 && iron >= 40)
        {
            archerAmt ++;
            archerAmount.text = [NSString stringWithFormat: @"%d", archerAmt];
            wood = wood - 55;
            stone = stone - 35;
            iron = iron - 40;
            woodCount.text = [NSString stringWithFormat:@"%d", wood];
            stoneCount.text = [NSString stringWithFormat:@"%d", stone];
            ironCount.text = [NSString stringWithFormat:@"%d", iron];
        }
        else if (cheapTroops == TRUE && wood >= 40 && stone >= 25 && iron >= 30)
        {
            archerAmt ++;
            archerAmount.text = [NSString stringWithFormat: @"%d", archerAmt];
            wood = wood - 40;
            stone = stone - 25;
            iron = iron - 30;
            woodCount.text = [NSString stringWithFormat:@"%d", wood];
            stoneCount.text = [NSString stringWithFormat:@"%d", stone];
            ironCount.text = [NSString stringWithFormat:@"%d", iron];
        }
    }
}

- (IBAction)cavalryBuy:(id)sender 
{
    if (infoCavalry == FALSE)
    {
        infoScroll.hidden = FALSE;
        infoText.hidden = FALSE;
        scrollbutton.hidden = FALSE;
        infoCavalry = TRUE;
        infoText.text = @"Cavalry are extremely strong offensive units. They have high attack and high plunder abilities. However, they are fairly expensive, and are weak while defending. For exact stats, see the help guide.";
    }
    else
    {
        if (cheapTroops == FALSE && wood >= 70 && stone >= 45 && iron >= 90)
        {
            cavalryAmt ++;
            cavalryAmount.text = [NSString stringWithFormat: @"%d", cavalryAmt];
            wood = wood - 70;
            stone = stone - 45;
            iron = iron - 90;
            woodCount.text = [NSString stringWithFormat:@"%d", wood];
            stoneCount.text = [NSString stringWithFormat:@"%d", stone];
            ironCount.text = [NSString stringWithFormat:@"%d", iron];
        }
        else if (cheapTroops == TRUE && wood >= 55 && stone >= 30 && iron >= 70)
        {
            cavalryAmt ++;
            cavalryAmount.text = [NSString stringWithFormat: @"%d", cavalryAmt];
            wood = wood - 55;
            stone = stone - 30;
            iron = iron - 70;
            woodCount.text = [NSString stringWithFormat:@"%d", wood];
            stoneCount.text = [NSString stringWithFormat:@"%d", stone];
            ironCount.text = [NSString stringWithFormat:@"%d", iron];
        }
    }
}

- (IBAction)catapultBuy:(id)sender 
{
    if (infoCatapult == FALSE)
    {
        infoScroll.hidden = FALSE;
        infoText.hidden = FALSE;
        scrollbutton.hidden = FALSE;
        infoCatapult = TRUE;
        infoText.text = @"Catapults are the highest offensive value units in the game. However, they have high costs and low plunder and defense values. Only use to declare war. For exact stats, see the help guide.";
    }
    else
    {
        if (cheapTroops == FALSE && wood >= 120 && stone >= 200 && iron >= 80)
        {
            catapultAmt ++;
            catapultAmount.text = [NSString stringWithFormat: @"%d", catapultAmt];
            wood = wood - 120;
            stone = stone - 200;
            iron = iron - 80;
            woodCount.text = [NSString stringWithFormat:@"%d", wood];
            stoneCount.text = [NSString stringWithFormat:@"%d", stone];
            ironCount.text = [NSString stringWithFormat:@"%d", iron];
        }
        else if (cheapTroops == TRUE && wood >= 100 && stone >= 170 && iron >= 65)
        {
            catapultAmt ++;
            catapultAmount.text = [NSString stringWithFormat: @"%d", catapultAmt];
            wood = wood - 100;
            stone = stone - 170;
            iron = iron - 65;
            woodCount.text = [NSString stringWithFormat:@"%d", wood];
            stoneCount.text = [NSString stringWithFormat:@"%d", stone];
            ironCount.text = [NSString stringWithFormat:@"%d", iron];
        }
    }
}

- (IBAction)help:(id)sender 
{
    recruitHelp1 = [self.storyboard instantiateViewControllerWithIdentifier:@"recruitHelp1"];
    [self presentModalViewController: recruitHelp1 animated:YES];
}

- (IBAction)scrollButton:(id)sender 
{
    scrollbutton.hidden = TRUE;
    infoScroll.hidden = TRUE;
    infoText.hidden = TRUE;
}
- (IBAction)figherInfoButton:(id)sender 
{
    infoScroll.hidden = FALSE;
    infoText.hidden = FALSE;
    scrollbutton.hidden = FALSE;
    infoFighter = TRUE;
    infoText.text = @"Fighter's are a cheap unit with offensive and defensive strengths, specialized in offense. They are decent for plundering resources but far outclassed by Cavalry. For exact stats, see the help guide.";
}

- (IBAction)archerInfoButton:(id)sender 
{
    infoScroll.hidden = FALSE;
    infoText.hidden = FALSE;
    scrollbutton.hidden = FALSE;
    infoArcher = TRUE;
    infoText.text = @"Archer's are the main defensive unit in this game. They have strong defensive stats and low costs, but are useless while attacking. They also have low plunder rates. For exact stats, see the help guide.";
}

- (IBAction)cavalryInfoButton:(id)sender 
{
    infoScroll.hidden = FALSE;
    infoText.hidden = FALSE;
    scrollbutton.hidden = FALSE;
    infoCavalry = TRUE;
    infoText.text = @"Cavalry are extremely strong offensive units. They have high attack and high plunder abilities. However, they are fairly expensive, and are weak while defending. For exact stats, see the help guide.";
}

- (IBAction)catapultInfoButton:(id)sender 
{
    infoScroll.hidden = FALSE;
    infoText.hidden = FALSE;
    scrollbutton.hidden = FALSE;
    infoCatapult = TRUE;
    infoText.text = @"Catapults are the highest offensive value units in the game. However, they have high costs and low plunder and defense values. Only use to declare war. For exact stats, see the help guide.";
}
@end
